package com.jackrain.nea.fc.pos.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wuwenxue
 * @date 2018/05/22
 **/
@Mapper
public interface ViewDLRetailToF4Mapper {

    @SelectProvider(type = ViewDLRetailSql.class, method = "findRetailData")
    List<HashMap> selRetailData(@Param("id") Object[] id,
                                @Param("acceptestatus") Integer acceptestatus,
                                @Param("isactive") String isactive);

    @SelectProvider(type = ViewDLRetailSql.class, method = "findRetailItemData")
    List<HashMap> selRetailItemData(@Param("id") Long id);

    @SelectProvider(type = ViewDLRetailSql.class, method = "findRetailPayItemData")
    List<HashMap> selRetailPayItemData(@Param("id") Long id);

    class ViewDLRetailSql {

        public String findRetailData(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            Integer acceptestatus = (Integer) map.get("acceptestatus");
            String isactive = (String) map.get("isactive");
            return new SQL() {
                {
                    SELECT("ID,BILL_NO,CP_C_STORE_ECODE,POS_NO,VP_C_VIP_ECODE,RETAIL_TYPE,TRANS_STATUS," +
                            "VIP_SCORE,SCORE_STATUS,CONSUME_SCORE,VIP_ADDRESS,VIP_ENAME,VIP_RECEIVER,VIP_TEL," +
                            "VIP_PRO,VIP_CITY,VIP_DIST,VIP_ADDRESS_REMARK,VIP_EXPRESS_TYPE,VIP_GET_TYPE,VIP_SCORE_NO," +
                            "WEB_FROM_NO,STATUS,STATUSNAME,STATUSTIME,BILL_DATE,REMARK,CREATIONDATE,OWNERNAME," +
                            "MODIFIERNAME,MODIFIERENAME,MODIFIEDDATE,ISPURRE,VIP_CITY,VARCHAR2");
                    FROM("DL_B_RETAIL");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("ID IN (" + sb.toString() + ")");
                    if (null != acceptestatus) {
                        WHERE("ACCEPTE_STATUS = " + acceptestatus);
                    }
                    if (null != isactive) {
                        WHERE("ISACTIVE = '" + isactive + "'");
                    }
                }
            }.toString();
        }

        public String findRetailItemData(Map<String, Object> map) {
            Long id = (Long) map.get("id");
            return new SQL() {
                {
                    SELECT("PS_C_SKU_ECODE,PRICE_LIST,CP_C_SALER_ENUMNO,SALE_TYPE,RETAIL_PRICE," +
                            "PRICE_RECEIVABLE,PRICE_ACTUAL,PRICE_COST,QTY_BILL,AMT_LIST,AMT_RETAIL,AMT_RECEIVABLE," +
                            "AMT_ACTUAL,AMT_COST,VIP_SCORE,CONSUME_SCORE,SCORE_STATUS,PROMOTION_ID,REMARK,RETAIL_TYPE,CP_C_SALER_ECODE");
                    FROM("DL_B_RETAIL_ITEM");
                    WHERE("DL_B_RETAIL_ID =" + id);
                }
            }.toString();
        }

        public String findRetailPayItemData(Map<String, Object> map) {
            Long id = (Long) map.get("id");
            return new SQL() {
                {
                    SELECT("PAY_WAY_CODE,PAY_AMT,REMARK,PAY_ACC,PAY_NO");
                    FROM("DL_B_RETAIL_PAY_ITEM");
                    WHERE("DL_B_RETAIL_ID =" + id);
                }
            }.toString();
        }


    }


}
